#include <iostream>
#include <string>
using namespace std;

class Animal
{
public:
    Animal()
    {
        std::cout << "Animal 构造函数" << std::endl;
    }

    virtual ~Animal()
    {
        std::cout << "Animal 析构函数" << std::endl;
    }

    virtual void speak()
    {
        std::cout << " Animal Speak" << std::endl;
    }
};

class Cat : public Animal
{
public:
    Cat(string name)
    {
        std::cout << " Cat 构造函数" << std::endl;
        m_name = new string(name);
    }

    ~Cat()
    {
        std::cout << " Cat 析构函数" << std::endl;
        delete m_name;
        m_name = nullptr;
    }
    void speak()
    {
        std::cout << *m_name << " Cat Speak" << std::endl;
    }

public:
    string *m_name;
};

int main()
{
    Animal *a = new Cat("Tom");
    a->speak();
    delete a;
}
/*
Animal 构造函数
 Cat 构造函数
Tom Cat Speak
 Cat 析构函数
Animal 析构函数
*/